function [likel, flag_ok] = lmj_likel_solexists(GG,RR,CONS,SDX,ZZ,Y,trainvec)
% =========================================================================
% LMJ_LIKEL_SOLEXISTS
flag_ok=-2;
likel=-1e40;
[T nn]=size(Y);
if any(CONS~=0)==1;Y=Y-repmat((ZZ*CONS)',[T 1]);end;
Y=Y';MM=RR*(SDX');
try
    pshat=disclyap_fast(GG,MM*(MM'));
    if ~isempty(find(isnan(pshat))~=0)
        disp('PSHAT contains Nan entries')
        return
    end
catch
    disp('Warning! Problems with initialization in GENSYSPOST_VEC');
    return
    flag_ok=-1;
end
shat=zeros(size(GG,1),1);lht=zeros(T,1);
try
    for ii=1:T;
        [shat,pshat,lht(ii)]=kf(Y(:,ii),ZZ,shat,pshat,GG,MM);
    end
catch
    disp('Warning! Problems with Kalman filter in GENSYSPOS');
    flag_ok=0;
    lasterror
    return
end
likel=-0.5*length(lht)*nn*log(2*pi)+sum(lht(trainvec(1):trainvec(2)));
flag_ok=1; 